| Conditions | 3 |
| Total Lines | 24 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import I18n from '@ioc:Adonis/Addons/I18n' |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Handle method is called by AdonisJS automatically on every middleware |
||
| 30 | * class. |
||
| 31 | */ |
||
| 32 | public async handle(ctx: HttpContextContract, next: () => Promise<void>) { |
||
| 33 | const language = this.getUserLanguage(ctx) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Switch locale when we are able to detect the user language and it |
||
| 37 | * is supported by the application |
||
| 38 | */ |
||
| 39 | if (language) { |
||
| 40 | ctx.i18n.switchLocale(language) |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Share i18n with view |
||
| 45 | */ |
||
| 46 | if ('view' in ctx) { |
||
| 47 | ctx.view.share({ i18n: ctx.i18n }) |
||
| 48 | } |
||
| 49 | |||
| 50 | await next() |
||
| 51 | } |
||
| 53 |